﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Projectmanagement.Entity;
using ProjectManagement.Models;
using Projectmanagement.Utl;
using Telerik.Web.Mvc;

namespace Projectmanagement.Controllers
{
    [RoleRequired]
    public class EmployeeController : Controller
    {
        public ActionResult Index()
        {
            return View();
        }

        [GridAction]
        public ActionResult _SelectIndex(int? conferenceid)
        {
            return View(new GridModel(DQ.GetEmployeeLocals().OrderBy(o=>o.EmployeeName)));
        }

        [AcceptVerbs(HttpVerbs.Post)]
        [GridAction]
        public ActionResult _SaveAjaxEditing(int id, int? conferenceid)
        {
            var item = CH.GetDataByID<EmployeeRolePM>(id);
            if (TryUpdateModel(item))
            {
                var ep = CH.DBAccount.EmployeeRoles.Find(item.EmployeeID);
                item.Name=ep.AccountName;
                CH.Edit(item);
            }
            return View(new GridModel(DQ.GetEmployeeLocals().OrderBy(o => o.EmployeeName)));
        }

        [AcceptVerbs(HttpVerbs.Post)]
        [GridAction]
        public ActionResult _InsertAjaxEditing(int? conferenceid)
        {
            var item = new EmployeeRolePM();
            //string Cotents = String.IsNullOrEmpty(Request["Contents"]) ? null : Request["Contents"].Trim();
            if (TryUpdateModel(item))
            {
                var ep = CH.DBAccount.EmployeeRoles.Find(item.EmployeeID);
                item.Name = ep.AccountName;
                CH.Create(item);
            }
            return View(new GridModel(DQ.GetEmployeeLocals().OrderBy(o => o.EmployeeName)));
        }

        [AcceptVerbs(HttpVerbs.Post)]
        [GridAction]
        public ActionResult _DeleteAjaxEditing(int id, int? conferenceid)
        {
            CH.Delete<EmployeeRolePM>(id);
            return View(new GridModel(DQ.GetEmployeeLocals().OrderBy(o => o.EmployeeName)));
        }
    }
}
